package com.ccjq.jq173.home;

import com.ccjq.jq173.product.po.Category;
import com.ccjq.jq173.product.po.Product;
import com.ccjq.jq173.product.po.Slider;
import com.ccjq.jq173.product.service.ProductService;
import com.ccjq.jq173.product.service.impl.ProductServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class HomeServlet extends HttpServlet {
    private static final long serialVersionUID = -1207970166648376051L;


    private ProductService service =null;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        service = new ProductServiceimpl();
        List<Slider> sliders = service.querySliders();
        List<Product> hotSales = service.queryHotSales();
        List<Category> categorys = service.queryCategorys();
        List<Product> newProducts = service.queryNewProducts();
        request.setAttribute("categorys", categorys);
        request.setAttribute("hotSales", hotSales);
        request.setAttribute("sliders", sliders);
        request.setAttribute("newProducts", newProducts);
        System.out.println(newProducts.size());
        request.getRequestDispatcher("/WEB-INF/jsp/home/home.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
